var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', ['$scope', '$http', function ($scope, $http) {
	/* body... */
	$http.get('/contactList').success(function (response) {
		/* body... */
		console.log('I get the data from I request');
		$scope.contactList = response;
	});
	var refresh = function () {
		/* body... */
		$http.get('/contactList').success(function (response) {
		/* body... */
			console.log('I get the data from I request');
			$scope.contactList = response;
			$scope.contact = '';
		});
	};
	$scope.addContact = function () {
		console.log('contact button clicked');
		/* body... */
		// alert($scope.contact.email);
		$http.post('/contactList', $scope.contact).success(function (response) {
			/* body... */
			console.log(response);
			refresh();
		});
	};
	$scope.remove = function (id) {
		/* body... */

		console.log(id);
		$http.delete('/contactList/' + id).success(function (response) {
			/* body... */
			refresh();
		});
	}
	$scope.edit = function (id) {
		/* body... */
		console.log(id);
		$http.get('/contactList/'+id).success(function (response) {
			/* body... */
			$scope.contact = response;
		});
	}
	$scope.update = function () {
		/* body... */
		$http.put('/contactList/' + $scope.contact._id, $scope.contact).success(function (response) {
			/* body... */
			refresh();
		});
	}
}]);
